package io.other_stream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class Demo_Print {
    public static void main(String[] args) throws IOException {
        Printer printer = new Printer(new FileOutputStream("7-14-1.txt"));
        printer.printInt(10000);
        printer.printDouble(3.1415);
        printer.printlnInt(111);
        printer.printlnDouble(9527.000);

        printer.close();

    }
}
class Printer {
    //定义OutPutStream
    OutputStream outputStream;

    public Printer(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    //写int的方法
    public void printInt(int a) throws IOException {
        //int ---> String
        String s = String.valueOf(a);
        outputStream.write(s.getBytes());
    }

    //写int的方法并且换行
    public void printlnInt(int a) throws IOException {
        //int ---> String
        String s = String.valueOf(a);
        outputStream.write(s.getBytes());
        outputStream.write(System.lineSeparator().getBytes());
    }

    //写double的方法
    public void printDouble(double d) throws IOException {
        //double ---> String
        String s = String.valueOf(d);
        outputStream.write(s.getBytes());
    }

    //写double的方法并且换行
    public void printlnDouble(double d) throws IOException {
        //double ---> String
        String s = String.valueOf(d);
        outputStream.write(s.getBytes());
        outputStream.write(System.lineSeparator().getBytes());
    }

    //写一个close方法释放资源
    public void close() throws IOException {
        outputStream.close();
    }


}
